﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Infrastructure.DataTypes
{
    public class Discrete : ICountable
    {
        private int m_iValue;
        private int m_maxValue = 5;
        private int m_minValue = 1;

        public static implicit operator int(Discrete d)
        {
            return d.m_iValue;
        }
        public static implicit operator Discrete( int iValue)
        {
            return new Discrete( iValue );
        }

        /// <summary>
        /// default constructor
        /// </summary>
        public Discrete()
        {
            m_iValue = 0;
        }
        /// <summary>
        /// default constructor
        /// </summary>
        public Discrete(int iValue)
        {
            m_iValue = iValue;
        }
        /// <summary>
        /// print value to string
        /// </summary>
        /// <returns></returns>
        public override String ToString()
        {
            return m_iValue.ToString();
        }
        /// <summary>
        /// implementation of ICountabke interface 
        /// convert the value to double
        /// </summary>
        /// <returns>returns double</returns>
        #region ICountable Members

        protected override double ToDouble()
        {
            return System.Convert.ToDouble(m_iValue);
        }

        public override double Value
        {
            get
            {
                return m_iValue;
            }
            set
            {
                m_iValue = (int)Math.Round(value);
            }
        }

        public override double MaxValue
        {
            get { return m_maxValue; }
        }

        public override double MinValue
        {
            get { return m_minValue; }
        }

        #endregion
    }
}
